<template>
  <div class="login-container">
    <div style="width: 400px; height: 400px; margin: 150px auto; background-color:rgba(165,190,234,0.5); border-radius: 10px">
      <div style="width: 100%; height: 100px; font-size: 30px; line-height: 100px; text-align: center; color: #4a5ed0">欢迎注册</div>
      <div style="margin-top: 25px; text-align: center; height: 320px;">
        <el-form :model="admin">
          <el-form-item>
            <el-input v-model="admin.name" prefix-icon="el-icon-user" style="width: 80%" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="admin.password" show-password prefix-icon="el-icon-lock" style="width: 80%" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-select v-model="admin.role" style="width: 80%" placeholder="请选择角色分类" >
              <el-option label="教师" value="ROLE_TEACHER"></el-option>
              <el-option label="学生" value="ROLE_STUDENT"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button style=" margin-top: 10px" type="primary" @click="login()">登录</el-button>
            <el-button style=" margin-top: 10px" type="primary" @click="register()">注册</el-button>
          </el-form-item>
        </el-form>

      </div>
    </div>
  </div>
</template>

<script>

import request from "@/utils/request";

export default {
  name: "Register",
  data() {
    return {
      admin: {}
    }
  },
  // 页面加载的时候，做一些事情，在created里面
  created() {
  },
  // 定义一些页面上控件出发的事件调用的方法
  methods: {
    register() {
      request.post("/user/register", this.admin).then(res => {
        if (res.code === '0') {
          this.$message.success("注册成功")
          this.$router.push("/login");
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    login() {
      this.$router.push("/login");
    }
  }
}
</script>
<style>
.login-container{
  height: 100vh;
  overflow: hidden;
  background-image: url("@/assets/A3.jpg");
  background-size: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>